<?xml version="1.0"?>
<docs>
    <doc id="Disposable">
<code lang="C#"><![CDATA[
public class HtmlCustomReader: HtmlTextReader
{
    private IDisposable managed;
    private IntPtr unmanagedHandle;
    private bool disposed;

    public HtmlCustomReader():
        base("data.html")
    {
        disposed = false;
        unmanagedHandle = Marshal.AllocHGlobal(256);
    }

    protected override void CheckDisposed()
    {
        if(disposed)
            throw new ObjectDisposedException("HtmlCustomReader",
                                              "The object has already been disposed!");
        base.CheckDisposed();
    }

    protected override void Dispose(bool disposing)
    {
        if(!disposed)
        {
            if(disposing)
            {
                managed.Dispose();
                managed = null;
            }
            Marshal.FreeHGlobal(unmanagedHandle);
            unmanagedHandle = IntPtr.Zero;
            disposed = true;
            Dispose(disposing);
        }
    }
}
]]></code>
<code lang="Visual Basic"><![CDATA[
Public Class HtmlCustomReader
    Inherits HtmlTextReader

	Private managed As IDisposable
	Private unmanagedHandle As IntPtr
	Private disposed As Boolean

	Public Sub New()
		MyBase.New("data.html")
		disposed = False
		unmanagedHandle = Marshal.AllocHGlobal(256)
	End Sub

	Protected Overloads Overrides Sub CheckDisposed()
		If disposed Then
			Throw New ObjectDisposedException("HtmlCustomReader",
			                                  "The object has already been disposed!")
		End If
		MyBase.CheckDisposed
	End Sub

	Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
		If Not disposed Then
			If disposing Then
				managed.Dispose
				managed = Nothing
			End If
			Marshal.FreeHGlobal(unmanagedHandle)
			unmanagedHandle = IntPtr.Zero
			disposed = True
			Dispose(disposing)
		End If
	End Sub
End Class
]]></code>
    </doc>
</docs>
